package com.luyue.zagj.activity.myAccount;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luyue.zagj.R;


import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UpdatePhoneActivity extends Activity {

    @Bind(R.id.UpdatePhone_cancel_btn)
    Button UpdatePhoneCancelBtn;
    @Bind(R.id.UpdatePhone_top_rl)
    RelativeLayout UpdatePhoneTopRl;
    @Bind(R.id.UpdatePhone_phone_ed)
    EditText UpdatePhonePhoneEd;
    @Bind(R.id.UpdatePhone_code_ed)
    EditText UpdatePhoneCodeEd;
    @Bind(R.id.UpdatePhone_get_code_tv)
    TextView UpdatePhoneGetCodeTv;
    @Bind(R.id.UpdatePhone_psw_ed)
    EditText UpdatePhonePswEd;
    @Bind(R.id.UpdatePhone_btn)
    Button UpdatePhoneBtn;
    private int i = 60;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_phone);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.UpdatePhone_cancel_btn, R.id.UpdatePhone_get_code_tv, R.id.UpdatePhone_btn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.UpdatePhone_cancel_btn:
                //返回
                onBackPressed();

                break;
            case R.id.UpdatePhone_get_code_tv:
                //获取验证码
                i=60;
                new sendThread().start();
                getCode();
                break;
            case R.id.UpdatePhone_btn:
                //确认

                Intent it=new Intent(this, SetActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(it);
                break;
        }
    }
    private void getCode() {
    }
    @Override
    protected void onResume() {
        super.onResume();
        i = 0;
    }


    class sendThread extends Thread {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                while (true) {
                    if (i <= 0) {
                        UpdatePhoneGetCodeTv.post(new Runnable() {
                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                i = 61;
                                UpdatePhoneGetCodeTv.setText("获取验证码");
                                UpdatePhoneGetCodeTv.setClickable(true);
                                //findPswPhoneGetCodeTv.setBackgroundResource(R.drawable.code);

                            }
                        });
                    } else if (i <= 60 && i > 0) {

                        UpdatePhoneGetCodeTv.post(new Runnable() {

                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                UpdatePhoneGetCodeTv.setText(i + "S");
                                UpdatePhoneGetCodeTv.setTextColor(0xffeeeeee);
                                UpdatePhoneGetCodeTv.setClickable(false);
                                UpdatePhoneGetCodeTv.setBackgroundResource(R.drawable.code_push);
                            }
                        });
                        i--;
                        Thread.sleep(1000);
                    }
                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
